<template>
    <div class="home">
        <section class="header-bar">
            <div class="logo">搜惠</div>
            <div class="search">
                <div class="search-btn">
                    <input placeholder="好宝贝 等你搜" readonly/>
                    <button class="search-icon"></button>
                </div>
            </div>
            <div class="cat"><em></em></div>
        </section>
        <div class="you-wrapper clearfix" id="more-goods">
            <div class="title-wrapper fl"></div>
            <!--<div class="text fl">-->
            <!--<span class="mui-badge mui-badge-blue main-badge">42225</span>-->
            <!--</div>-->
        </div>
        <section class="goods-list"
                 infinite-scroll-disabled="loading"
                 v-infinite-scroll="loadMore"
                 infinite-scroll-distance="20">
            <div class="goods-item" v-for="item in items" @click="$router.push({path:'/detail?iid='+item.iid})">
                <a class="img">
                    <span class="coupon-wrapper">券 <i>￥</i><b>30</b></span> <span class="today-wrapper">精选</span>
                    <!--<img :src="item.picUrl+'_310x310.jpg'" alt="">-->
                    <img v-lazy="item.picUrl+'_310x310.jpg'">
                </a>
                <a class="title">
                    <div class="text" style=" color:#777777;">
                        {{item.title}}
                    </div>
                </a>
                <div class="price-wrapper">
                    <span class="text">券后</span>
                    <span class="price">￥{{getPromoPrice(item.price, item.couponTotalCount)}}</span>
                    <div class="sold-wrapper">
                        <span class="sold-num">{{item.saleQuantity}}</span>
                        <span class="text">人已买</span>
                    </div>
                </div>
            </div>
            <div>正在加载下一页....</div>
        </section>
        <!--<section class="pullup-goods">-->
        <!--<div class="label">商品加载中...</div>-->
        <!--</section>-->
    </div>
</template>
<script>
    //    import {InfiniteScroll} from 'mint-ui';

    export default {
        data() {
            return {
                loading: false,
                items  : []
            }
        },
        created() {
            this.$http.get('/api/goods/items/list-show').then(rsp => {
                this.items = rsp.data.data.content
            })
        },
        methods: {
            loadMore() {
                this.loading = true;
                setTimeout(() => {
                    this.$http.get('/api/goods/items/list-show').then(rsp => {
                        this.items = [...this.items, ...rsp.data.data.content];
                        this.loading = false;
                    });
                }, 300);
            },
            getPromoPrice(price, couponTotalCount) {
                let _price = price * 100 - couponTotalCount;
                return _price / 100;
            }
        }
    }
</script>
<style rel="stylesheet/scss" lang="scss">
    .home {
        background-color: red;
        padding-top: 44px;
        .header-bar {
            background: #fe4a65;
            position: fixed;
            width: 100%;
            display: flex;
            top: 0;
            height: 44px;
            padding: 8px 10px;
            z-index: 999;
            .logo {
                width: 50px;
                text-align: center;
                display: inline-flex;
                color: white;
                font-size: 19px;
                justify-content: center;
                align-items: center;

            }
            .search {
                flex: 1;
                display: inline-flex;
                padding: 0 9px;
                position: relative;
                width: 100%;
                .search-btn {
                    height: 100%;
                    width: 100%;
                    background: white;
                    border-radius: 5px;
                    padding: 0 10px;
                    input {
                        border: none;
                        padding: 0;
                        height: 100%;
                    }
                }
                .search-icon {
                    position: absolute;
                    width: 24px;
                    height: 24px;
                    top: 2px;
                    border: none;
                    display: block;
                    background: url('/assets/static/img/icon.png') 6px -26px no-repeat;
                    background-size: 287px 800px;
                    right: 13px;
                }

            }
            .cat {
                display: inline-flex;
                em {
                    background: url('/assets/static/img/icon.png') 0 2px no-repeat;
                    background-size: 287px 800px;
                    width: 28px;
                    height: 28px;
                }
            }
        }
        .you-wrapper {
            padding: 11px 11px 8px;
            background: white;
            height: 16px;
            box-sizing: content-box;
            .title-wrapper {
                color: #363535;
                width: 110px;
                height: 16px;
                background: url('~assets/static/img/icon.png') -13px -29px no-repeat;
                background-size: 287px 800px;
                padding-left: .5rem;
                border-left: 3px solid #fe4a65;
            }
            .text {
                background: #ffe5ec;
                color: #fe4a65;
                height: 16px;
                padding: 0 5px;
                margin-left: 9px;
                border-radius: 4px;
                line-height: 16px;
                font-size: 12px;
            }
        }
        .goods-list {
            background-color: #fff;
            padding: 0.2em;
            padding-top: 0.4em;
            text-align: center;
            overflow: hidden;
            .goods-item {
                width: 48%;
                display: block;
                text-align: left;
                margin-bottom: 0.7em;
                margin-left: 0.15em;
                float: left;
                &:nth-child(2n) {
                    margin-right: 0.15em;
                    float: right;
                }
                a.title {
                    width: 100%;
                    margin-top: 0.2em;
                    display: block;
                    .text {
                        color: #777777;
                        word-break: break-all;
                        width: 100%;
                        overflow: hidden;
                        font-size: 12px;
                        line-height: 18px;
                        text-align: center;
                        height: 18px;
                    }
                }
                .price-wrapper {
                    position: relative;
                    margin: 0.2em 0;
                    .text {
                        color: #a3a3a3;
                        font-size: 12px;
                        display: inline-block;
                    }
                    .price {
                        color: #ff4b5f;
                        font-size: 14px;
                        margin-left: -0.3em;
                        display: inline-block;
                        margin-top: 0.1em;
                    }
                    .sold-wrapper {
                        position: absolute;
                        right: 0;
                        top: 0.05em;
                        .sold-num {
                            color: #ecabab;
                            font-size: 10px;
                        }
                        .text {
                            color: #a3a3a3;
                            font-size: 10px;
                        }
                    }
                }
                a.img {
                    padding-bottom: 100%;
                    height: 0;
                    background: #f5f5f5;
                    width: 100%;
                    position: relative;
                    display: block;
                    img {
                        width: 100%;
                        border: none;
                        vertical-align: top;
                        margin-top: -1rem;
                    }
                    .today-wrapper {
                        background-color: #7ad3c1;
                        position: relative;
                        z-index: 10;
                        font-size: 10px;
                        text-align: center;
                        /*background-color: #e53563;*/
                        height: 1rem;
                        line-height: 1rem;
                        color: #fff;
                        float: right;
                        padding: 0px 5px;
                        font-family: "Microsoft Yahei";
                    }
                    .coupon-wrapper {
                        position: relative;
                        z-index: 10;
                        font-size: 10px;
                        text-align: center;
                        background-color: #e53563;
                        height: 1rem;
                        line-height: 1rem;
                        color: #fff;
                        float: right;
                        padding: 0px 5px;
                        font-family: "Microsoft Yahei";
                    }
                }
            }
        }
        .pullup-goods {
            font-size: 12px;
            height: 50px;
            display: block;
            line-height: 50px;
            color: #565656;
            text-align: center;
            background-color: #fff;
        }
    }
</style>